<!DOCTYPE HTML>
<html lang="cn" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
    <%include("/common/header.html",{title:''}){}%>
    <title>个人商家认证管理</title>
</head>
<body>


<div class="x-nav" style="margin-top: 30px;margin-left: 30px">
      <span class="layui-breadcrumb" lay-filter="breadcrumb" style="visibility: visible;">
        <a href="javascript:;">首页</a><span lay-separator="">/</span>
        <a href="javascript:;">会员管理</a><span lay-separator="">/</span>
          <a href="javascript:;">商家认证管理</a><span lay-separator="">/</span>
        <a><cite>个人商家认证管理</cite></a>
      </span>
    <a class="layui-btn layui-btn-primary layui-btn-small" style="margin-top:4px;float:right;" href="javascript:location.replace(location.href)"; title="刷新">
        <i class="layui-icon layui-icon-refresh-3"></i>
    </a>
</div>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <table id="LAY-user-manage" lay-filter="LAY-user-manage"></table>
            <script type="text/html" id="toolbarDemo">
                <button class="layui-btn layuiadmin-btn-useradmin">个人商家信息</button>
            </script>
            <script type="text/html" id="table-useradmin-webuser">
                {{#  if(d.code==2){ }}
                <a class="layui-btn layui-btn-normal layui-btn-xs" id="edit" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
                <a id="agree" class="layui-btn layui-btn-normal layui-btn-xs" lay-event="agree"><i class="layui-icon layui-icon-edit"></i>同意申请</a>
                <a id="refuse" class="layui-btn layui-btn-normal layui-btn-xs" lay-event="refuse"><i class="layui-icon layui-icon-edit"></i>拒绝申请</a>
                {{#  }else if( d.code==0){ }}
                <a style="margin-left: 25px;" class="layui-btn layui-btn-normal layui-btn-xs" lay-event="view"><i class="layui-icon layui-icon-edit"></i>查看</a>
                <a id="agreed" class="layui-btn layui-btn-normal layui-btn-xs" style="background-color: gray;margin-left: 50px;" lay-event=""><i class="layui-icon layui-icon-edit"></i>已同意</a>
                {{#  }else if( d.code==1){ }}
                <a style="margin-left: 12px;" class="layui-btn layui-btn-normal layui-btn-xs" id="reason1" lay-event="reason1"><i class="layui-icon layui-icon-edit"></i>拒绝原因</a>
                <a id="refused" class="layui-btn layui-btn-normal layui-btn-xs" style="background-color: gray;margin-left: 10px;" lay-event=""><i class="layui-icon layui-icon-edit"></i>已拒绝</a>
                {{#  } }}
            </script>
        </div>
    </div>
</div>

<!-- 弹出查看页面 -->
<div class="layui-form" lay-filter="layuiadmin-form-useradmin"
     id="layuiadmin-form-useradmin1"
     style="padding: 15px;display: none">
    <form action class="layui-form" lay-filter="component-form-element1" id="myform1">
        <div class="layui-form-item">
            <label class="layui-form-label" style="padding-left: 0px;font-size: medium;width: auto;">手艺人姓名:</label>
            <div class="layui-input-inline">
                <input type="text" id="name1" name="name" disabled class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label" style="padding-left: 0px;font-size: medium;width: auto;">性别:</label>
            <div class="layui-input-inline">
                <input type="text" id="sex1" name="sex" disabled class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label" style="padding-left: 0px;font-size: medium;width: auto;">手机号码:</label>
            <div class="layui-input-inline">
                <input disabled style="float:left;width: 140px;" type="text" id="phone1" name="phone" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label" style="padding-left: 0px;font-size: medium;width: auto;">养老从业年限:</label>
            <div class="layui-input-inline">
                <input disabled style="float:left;width: 140px;" type="text" id="worktime1" name="worktime" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label" style="padding-left: 0px;font-size: medium;width: auto;">养老从业经历:</label>
            <div class="layui-input-inline" style="width: 555px">
                <textarea disabled class="layui-textarea" type="text" id="workexperience1" name="workexperience" ></textarea>
            </div>
        </div>



        <div class="layui-form-item">
            <label class="layui-form-label" style="padding-left: 0px;font-size: medium;width: auto;">专长分类:</label>
            <div class="layui-input-inline">
                <input disabled style="float:left;width: 140px;" type="text" id="f_classify1" name="f_classify" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label" style="padding-left: 0px;font-size: medium;width: auto;">专长子分类:</label>
            <div class="layui-input-inline">
                <input disabled type="text" id="s_classify1" name="s_classify" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label" style="padding-left: 0px;font-size: medium;width: auto;">信息渠道:</label>
            <div class="layui-input-inline">
                <input disabled style="float:left;width: 140px;" type="text" id="channel1" name="channel" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label" style="padding-left: 0px;font-size: medium;width: auto;">报名类型:</label>
            <div class="layui-input-inline">
                <input disabled type="text" id="type11" name="type1" class="layui-input">
            </div>
        </div>
    </form>
</div>

<!-- 弹出修改页面 -->
<div class="layui-form" lay-filter="layuiadmin-form-useradmin"
     id="layuiadmin-form-useradmin"
     style="padding: 15px;display: none">
    <form action class="layui-form" lay-filter="component-form-element" id="myform">
        <input type="hidden"  name="Nature" id="Nature" value="1"/>
        <input type="hidden" name="id">
        <input type="hidden" name="account">
        <div class="layui-form-item">
            <label class="layui-form-label" style="padding-left: 0px;font-size: medium;width: auto;">手艺人姓名:</label>
            <div class="layui-input-inline">
                <input type="text" name="name" lay-verify="required" value="" class="layui-input"
                       placeholder="请输入手艺人姓名">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label" style="padding-left: 0px;font-size: medium;width: auto;">性别:</label>
            <div class="layui-input-inline">
                <input checked type="radio" name="sex" lay-verify="required" value="男" class="layui-radio"
                       placeholder="请选择技师性别"><span style="position: absolute;left: 27px;top: 10px;">男</span>
                <input type="radio" name="sex" lay-verify="required" value="女" class="layui-radio"
                       placeholder="请选择技师性别"><span style="position: absolute;left: 80px;top: 10px;">女</span>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label" style="padding-left: 0px;font-size: medium;width: auto;">手机号码:</label>
            <div class="layui-input-inline">
                <input type="text" name="phone" lay-verify="required" value="" class="layui-input"
                       placeholder="请输入手机号码">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label" style="padding-left: 0px;font-size: medium;width: auto;">养老从业年限:</label>
            <div class="layui-input-inline">
                <select style="float:left;width: 140px;" type="text" name="worktime" lay-verify="required" value="" class="layui-input"
                       placeholder="请输入养老从业年限">
                    <option value="一年以下">一年以下</option>
                    <option value="1-3年">1-3年</option>
                    <option value="3-5年">3-5年</option>
                    <option value="5年以上">5年以上</option>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label" style="padding-left: 0px;font-size: medium;width: auto;">养老从业经历:</label>
            <div class="layui-input-inline" style="width: 555px">
                <textarea id="introduce" type="text" style="display: none" name="workexperience" lay-verify="content"></textarea>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label" style="padding-left: 0px;font-size: medium;width: auto;">专长父分类:</label>
            <div class="layui-input-inline">
                <select lay-filter="f_classify" style="height: 40px;width: 70px" lay-verify="required" id="classifys" name="f_classify">
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label" style="padding-left: 0px;font-size: medium;width: auto;">专长子分类:</label>
            <div class="layui-input-inline">
                <select style="height: 40px;width: 70px" lay-verify="required" id="s_classify" name="s_classify">
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label" style="padding-left: 0px;font-size: medium;width: auto;">信息渠道:</label>
            <div class="layui-input-inline">
                <input checked type="radio" name="channel" lay-verify="required" value="熟人推荐" class="layui-radio"
                       placeholder="请选择信息渠道"><span>熟人推荐</span></br>
                <input type="radio" name="channel" lay-verify="required" value="求职网站" class="layui-radio"
                       placeholder="请选择信息渠道"><span>求职网站</span></br>
                <input type="radio" name="channel" lay-verify="required" value="广告" class="layui-radio"
                       placeholder="请选择信息渠道"><span>广告</span></br>
                <input type="radio" name="channel" lay-verify="required" value="其他" class="layui-radio"
                       placeholder="请选择信息渠道"><span>其他</span>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label" style="padding-left: 0px;font-size: medium;width: auto;">报名类型:</label>
            <div class="layui-input-inline">
                <input checked type="radio" name="type1" lay-verify="required" value="全职手艺人" class="layui-radio"
                       placeholder="请选择报名类型"><span>全职手艺人</span></br>
                <input type="radio" name="type1" lay-verify="required" value="兼职手艺人" class="layui-radio"
                       placeholder="请选择报名类型"><span>兼职手艺人</span></br>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block" style="margin-left: 240px;">
                <button class="layui-btn" lay-submit="" lay-filter="component-form-element">立即提交</button>
            </div>
        </div>
    </form>
</div>
<script id="demo" type="text/html">
    <option value="">请选择</option>
    {{#  layui.each(d.list, function(index, item){ }}

    <option {{d.classify== item.name?"selected":""}} value="{{ item.id }}">{{ item.name }}</option>

    {{#  }); }}
    <option {{d.classify== "餐饮"?"selected":""}} value="-1">餐饮</option>
    {{#  if(d.list.length === 0){ }}
    无数据
    {{#  } }}
</script>
<script id="demo2" type="text/html">
    <!--<option value="">请选择</option>-->
    {{#  layui.each(d.list2, function(index, item2){ }}

    <option {{d.s_classify== item2.name?"selected":""}} value="{{ item2.name }}">{{ item2.name }}</option>

    {{#  }); }}
    {{#  if(d.list2.length === 0){ }}
    <option disabled value="">无</option>
    {{#  } }}
</script>

</div>
<%include("/common/foot.html"){}%>
<script>
    layui.config({
        base : 'static/layuiadmin/' //静态资源所在路径
    }).extend({
        index : 'lib/index' //主入口模块
    }).use([ 'index', 'table','form','layedit','laydate'], function() {
        var $ = layui.$;
        var table = layui.table;
        var form = layui.form;
        var title="志愿者招募";
        var size=['600px', '500px'];
        var findAll_url='system/personal/findAll.json';
        var agree_url='system/personal/agree.json';
        var refuse_url='system/personal/refuse.json';
        var update_url='system/personal/update.json';
        var index;//定义建立富文本编辑器全局变量
        var layedit//定义富文本编辑器layedit全局变量
        var cols=[ //表头
            {field: 'name', width:"150" ,title: '手艺人姓名',fixed: 'left'},
            {field: 'sex', width:"150" ,title: '性别'},
            {field: 'phone', width:"150" ,title: '手艺人手机'},
            {field: 'worktime', width:"150" ,title: '养老从业年限'},
            {field: 'workexperience', width:"150" ,title: '养老从业经历'},
            {field: 'f_classify', width:"150" ,title: '专长总分类'},
            {field: 's_classify', width:"150" ,title: '专长分类'},
            {field: 'channel', width:"150" ,title: '信息渠道'},
            {field: 'type1', width:"150" ,title: '报名类型'},
            /*{
                field: 'logo',
                width: "110",
                title: '个人logo',
                templet: "<div><img src={{d.logo}} style='width:30px;height:30px'></div>"
            },*/
            {title:'操作', width:270, toolbar: '#table-useradmin-webuser',fixed: 'right'}
        ]

        table.render({
            elem: '#LAY-user-manage',
            id: 'listReload',
            toolbar: '#toolbarDemo',
            title: title,
            url: findAll_url,
            page: true, //开启分页
            limits: [10, 20, 30, 50], //控制多少行一页（默认五条一页）
            defaultToolbar: ['filter', 'print', 'exports'],
            cols: [cols],
            done() {
                //alert() 数据渲染完的方法
            }
        });

        //初始化修改页面

        function loadData(data) {

            var ret = {
                "id": data.id,
                // "classify": data.classifys.name,
                "sex": data.sex,
                "name": data.name,
                "phone": data.phone,
                "worktime": data.worktime,
                "workexperience": data.workexperience,
                "f_classify": data.f_classify,
                "s_classify": data.s_classify,
                "channel": data.channel,
                "type1": data.type1,
                "account": data.account,
            }
            // $("#img1").attr("src", data.img);
            // $("#classifys").val(data.classifys.id);
            // $("#introduce").val(data.introduce);
            form.render();
            return ret;
        }

        //编辑
        function initUpdate(data) {
            var a = layer.open({
                type: 1,
                title: title,
                content: $('#layuiadmin-form-useradmin'),
                btn: ['关闭'], //可以无限个按钮
                cancel: function (index, layero) {//取消事件
                    location.replace(location.href);　//layer.open关闭刷新
                },
                success: function (layero, index) {
                    layer.iframeAuto(index);
                }
            });
            layer.full(a);
            //服务分类
            $.ajax({
                url: "system/classify/getF.json",
                type: "POST",
                data:{
                },
                dataType: "json",
                success: function(ret){
                    var laytpl = layui.laytpl;
                    var rets = { //数据
                        "list": ret,
                        classify: data.f_classify
                    };
                    laytpl($("#demo").html()).render(rets, function (html) {
                        $("#classifys").html(html);
                    });
                    // $("#classifys").val(ret.name);
                    form.render();

                },
                error:function(jqXHR, textStatus, errorThrown){

                }
            });
            var fid;
            if(null!=data.classifys){
                fid = data.classifys.id
            }else{
                fid = -1
            }
            $.ajax({
                url: "system/classify/getS.json",
                type: "POST",
                data:{
                    fid: fid
                },
                dataType: "json",
                success: function(ret){
                    var laytpl = layui.laytpl;
                    var ret2 = { //数据
                        "list2": ret,
                        s_classify: data.s_classify
                    };
                    laytpl($("#demo2").html()).render(ret2, function (html) {
                        $("#s_classify").html(html);
                    });
                    form.render();

                },
                error:function(jqXHR, textStatus, errorThrown){

                }
            });
            //富文本编辑器
            layedit = layui.layedit;
            //建立编辑器
            index = layedit.build('introduce', {
                tool: ['strong', 'italic', 'underline', 'del', '|',
                    'left', 'center', 'right', '|',
                    'link', 'unlink',],
                height: 280
            });

            //富文本表单验证
            form.verify({
                introduce: function (value) {
                    var val = layedit.getText(index);
                    //alert(val.length)
                    if (val.length < 6) {

                        return '内容至少6个字符'
                    }
                }
            });
            //如果是添加则重置表单，如果是编辑则给表单赋值
            if (data == 0 || data == null) {
                $('#myform')[0].reset();
                return;
            } else {
                layui.form.val("component-form-element", loadData(data));
            }
        }

        //弹出查看页面调用初始化数据方法
        function initUpdate1(data) {
            var a = layer.open({
                type: 1,
                title: title,
                content: $('#layuiadmin-form-useradmin1'),
                btn: ['关闭'], //可以无限个按钮
                cancel: function (index, layero) {//取消事件
                    //location.replace(location.href);　//layer.open关闭刷新
                },
                success: function (layero, index) {
                    layer.iframeAuto(index);
                }
            });
            layer.full(a);
            //给表单赋值
            $("#f_classify1").val(data.f_classify);
            $("#s_classify1").val(data.s_classify);
            $("#name1").val(data.name);
            var workexperience=data.workexperience;
            workexperience = workexperience.replace(/(\n)/g, "");
            workexperience = workexperience.replace(/(\t)/g, "");
            workexperience = workexperience.replace(/(\r)/g, "");
            workexperience = workexperience.replace(/<\/?[^>]*>/g, "");
            workexperience = workexperience.replace(/\s*/g, "");
            $("#workexperience1").val(workexperience);
            $("#sex1").val(data.sex);
            $("#phone1").val(data.phone);
            $("#worktime1").val(data.worktime);
            $("#channel1").val(data.channel);
            $("#type11").val(data.type1);
            //layui.form.val("component-form-element1", loadData(data));

        }

        //子分类联动
        form.on('select(f_classify)', function (data) {
            var f_classify=data.value;
            f_classify = f_classify.replace("\"","").replace("\"","");
            var f_classify = parseInt(f_classify);
            $.ajax({
                url: "system/classify/getS.json",
                type: "POST",
                data:{
                    fid:f_classify
                },
                dataType: "json",
                success: function(ret){
                    var laytpl = layui.laytpl;
                    var ret2 = { //数据
                        "list2": ret,
                        s_classify: data.s_classify
                    };
                    laytpl($("#demo2").html()).render(ret2, function (html) {
                        $("#s_classify").html(html);
                    });
                    form.render();

                },
                error:function(jqXHR, textStatus, errorThrown){

                }
            });
            $("#areaid").empty();
            //$("#qqq").show();
            //alert(JSON.stringify(data.value))
        });

        //修改页面的内容提交到后台处理
        form.on('submit(component-form-element)', function (data) {
            data.field.workexperience = layedit.getContent(index);
            postUpdate(data);
            return false;
        });

        //点击每行右工具栏“操作”里面按钮效果
        table.on('tool(LAY-user-manage)', function(obj) {
            var data = obj.data;
            if (obj.event === 'agree') {
                $.ajax({
                    url : agree_url,
                    type : "POST",
                    data : {
                        "id" : data.id,
                    },
                    dataType : "json",
                    success : function(ret) {
                        //alert(ret.code)
                        layer.msg(ret.msg, {icon: 6});

                        setTimeout(function (){

                            window.location.reload();
                        }, 1000);

                    },
                    error:function(jqXHR, textStatus, errorThrown){
                        var estr="Page:"+window.location.pathname+",Function: postDelete()";
                        layer.open({
                            title: "错误信息",
                            area: ['600px', '600px'],
                            type: 2,
                            content: "base/error.jhtml?info="+estr, //
                            btn: ['关闭'] //可以无限个按钮
                        });
                    }
                });
            } else if(obj.event === 'edit'){
                $("#edit").attr({"disabled":"disabled"});
                initUpdate(data);
            } else if (obj.event === 'view') {
                $("#view").attr({"disabled":"disabled"});
                initUpdate1(data);
            } else if(obj.event === 'refuse'){
                $("#refuse").attr({"disabled":"disabled"});
                layer.prompt({title: '请输入驳回原因', formType: 2}, function(text, index){
                    layer.close(index);
                    $.ajax({
                        url : refuse_url,
                        type : "POST",
                        data : {
                            "id" : data.id,
                            "code" : 1,
                            "reason1" : text
                        },
                        dataType : "json",
                        success : function(ret) {
                            layer.msg(ret.msg, {icon: 6});
                            setTimeout(function (){
                                window.location.reload();
                            }, 1000);
                        },
                        error:function(jqXHR, textStatus, errorThrown){
                            var estr="Page:"+window.location.pathname+",Function: postDelete()";
                            layer.open({
                                title: "错误信息",
                                area: ['600px', '600px'],
                                type: 2,
                                content: "base/error.jhtml?info="+estr, //
                                btn: ['关闭'] //可以无限个按钮
                            });
                        }
                    });
                });
            } else if (obj.event === 'reason1') {
                $("#reason1").attr({"disabled":"disabled"});
                layer.alert(data.reason1)
            }
        });

        //ajax提交修改内容
        window.postUpdate = function (data) {
            var formData = new FormData();
            formData.append("data", JSON.stringify(data.field));
            // formData.append("file", $("input[name='file']")[0].files[0]);
            $.ajax({
                url: update_url,
                type: "POST",
                //traditional:true,
                data: formData,
                processData: false,
                contentType: false,
                success: function (data) {
                    if (data.code == 1) {
                        layer.closeAll();
                        layer.msg(data.msg, {time: 600, icon: 1}, function () {
                            //table.reload('listReload');
                            location.replace(location.href);
                        });
                    } else {
                        layer.msg(data.msg, {icon: 5});
                    }
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    var estr = "Page:" + window.location.pathname + ",Function:postUpdate()";
                    layer.open({
                        title: "错误信息",
                        type: 2,
                        content: "base/error.jhtml?info=" + estr,
                        btn: ['关闭'] //可以无限个按钮
                    });
                }
            });
        }

    });

</script>
</body>

</html>
